/*
 * @Description:
 * @Version: 1.0
 * @Author: wenbin
 * @Date: 2021-09-15 10:30:44
 * @LastEditors: wenbin
 * @LastEditTime: 2021-11-15 16:11:13
 * @FilePath: /vite-ts-vue3-test/src/router/index.ts
 * Copyright (C) 2021 wenbin. All rights reserved.
 */
/*
 * @Descripttion: 路由配置文件  参考文档：https://next.router.vuejs.org/zh/introduction.html
 */
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/home/index.vue'),
    children: [],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    children: [],
    meta: {
      isNeedLayout: false,
      title: '登陆',
    },
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/notFound/index.vue'),
    meta: {
      isNeedLayout: false,
      title: 'Error',
    },
  },
  {
    path: '/:pathMatch(.*)', // 和以前配置有所不一样 or  /:catchAll(.*)
    redirect: '/404',
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 路由配置上定义 路由独享的守卫
// beforeEnter: (to, from) => {
//   // reject the navigation
//   return false
// },

// 导航守卫
// onBeforeRouteLeave, onBeforeRouteUpdate

export default router;
